#include "settings.h"


Settings::Settings()
{
    _resetParams();
}


bool Settings::parseFromCommandLine(QStringList &commanLineParams)
{
    _resetParams();


    //first argument is program name
    int incrementValue = 2;
    for(int i=1; i<commanLineParams.length(); i+=incrementValue)
    {
        QString paramName = commanLineParams[i];        
        QString paramValue = "";
        if(i+1 < commanLineParams.length())
        {
            paramValue = commanLineParams[i+1];
        }
        if(paramValue.startsWith("-"))
        {
            paramValue = "";
            incrementValue = 1;
        }
        else
        {
            incrementValue = 2;
        }

        if(SETTINGS_FILE_PARAM == paramName)
        {
            _filePath = paramValue;
        }
        else if(SETTINGS_DB_SERVER_PARAM == paramName)
        {
            _dbServer = paramValue;
        }
        else if(SETTINGS_DB_NAME_PARAM == paramName)
        {
            _dbName = paramValue;
        }
        else if(SETTINGS_DB_USER_PARAM == paramName)
        {
            _dbUser = paramValue;
        }
        else if(SETTINGS_DB_PASSWORD_PARAM == paramName)
        {
            _dbPassword = paramValue;
        }
    }

    return  _filePath.length() > 0 &&
            _dbServer.length() > 0 &&
            _dbName.length() > 0 &&
            _dbUser.length() > 0;
}


void Settings::_resetParams()
{
    _filePath = "";
    _dbServer = "";
    _dbName = "";
    _dbUser = "";
    _dbPassword = "";
}


QString Settings::getFilePath()
{
    return _filePath;
}

QString Settings::getDbServer()
{
    return _dbServer;
}

QString Settings::getDbName()
{
    return _dbName;
}

QString Settings::getDbUser()
{
    return _dbUser;
}

QString Settings::getDbPassword()
{
    return _dbPassword;
}
